package com.sale.goods.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.goods.domain.dto.GoodsPaymentDto;
import com.sale.goods.domain.vo.GoodsPaymentVo;
import com.sale.goods.service.IGoodsPaymentService;
import com.sale.goods.api.dto.GoodsMessageBySupplierDto;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description 付款单
 * @Date 23-07-19
 * @Author hl
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/payment")
public class GoodsPaymentController extends BaseController {

    private final IGoodsPaymentService goodsPaymentService;


    /**
     * 获取付款单
     */
    //@SaCheckPermission("finance:payment:index")
    @GetMapping("/list")
    public TableDataInfo<GoodsPaymentDto> list(GoodsPaymentVo goodsPaymentVo, PageQuery pageQuery) {
        return goodsPaymentService.selectPaymentList(goodsPaymentVo, pageQuery);
    }

    /**
     * 新增付款单
     */
    //@SaCheckPermission("finance:payment:iadd")
    @Log(title = "付款单", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody GoodsPaymentVo goodsPaymentVo) throws Exception {
        return toAjax(goodsPaymentService.insertPayment(goodsPaymentVo));
    }

    /**
     * 根据编号获取详细信息
     */
    //@SaCheckPermission("finance:payment:iquery")
    @GetMapping(value = "/{paymentId}")
    public R getInfo(@PathVariable long paymentId) {
        return R.ok(goodsPaymentService.selectPaymentById(paymentId));
    }

    /**
     * 删除付款单
     */
    //@SaCheckPermission("finance:payment:iremove")
    @Log(title = "付款单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{paymentId}")
    public R<Void> remove(@PathVariable("paymentId") Long paymentId) {
        return toAjax(goodsPaymentService.deletePaymentById(paymentId));
    }

    /**
     * 修改付款单
     */
    //@SaCheckPermission("finance:payment:iedit")
    @Log(title = "付款单", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody GoodsPaymentVo goodsPaymentVo) {
        return toAjax(goodsPaymentService.updatePaymentEdit(goodsPaymentVo));
    }

    /**
     * 提交审核
     */
    //@SaCheckPermission("finance:payment:isubExamine")
    @Log(title = "付款单", businessType = BusinessType.UPDATE)
    @GetMapping("/submitReview/{paymentId}")
    public R<Void> submitReview(@PathVariable("paymentId") Long paymentId) {
        return toAjax(goodsPaymentService.submitReview(paymentId));
    }

    /**
     * 撤销审核
     */
    //@SaCheckPermission("finance:payment:irevoke")
    @Log(title = "付款单", businessType = BusinessType.UPDATE)
    @GetMapping("/deleteReview/{paymentId}")
    public R<Void> deleteReview(@PathVariable("paymentId") Long paymentId) {
        return toAjax(goodsPaymentService.deleteReview(paymentId));
    }

    /**
     * 审核单据
     */
    //@SaCheckPermission("finance:payment:iexamine")
    @Log(title = "付款单", businessType = BusinessType.UPDATE)
    @PostMapping("/examine")
    public R<Void> examine(@Validated @RequestBody GoodsPaymentVo goodsPaymentVo) throws Exception {
        return toAjax(goodsPaymentService.goodSExamineReview(goodsPaymentVo));
    }

    /**
     * 工作台接口(采购已收款金额)
     */
    @GetMapping("/received")
    public String received() {
        return goodsPaymentService.goodsReceived();
    }

    /**
     * 工作台接口(采购未付款金额)
     */
    @GetMapping("/arrears")
    public String arrears() {
        return goodsPaymentService.goodsArrears();
    }

    /**
     * 根据供应商分组获取已核销金额、整单折扣
     */
    @GetMapping("/getGoodsMessageBySupplier")
    public Map<String, GoodsMessageBySupplierDto> getGoodsMessageBySupplier() {
        return goodsPaymentService.getGoodsMessageBySupplier();
    }

}

